"""
计算用户位置的类

"""

# 模型训练模型
import math


class ModelTranModule(object):
    def GaussianGiter(self,rssis):
        """

        :param rssis: 扫描到的信标信号强度[]
        :return:
        """
        sum = sum(rssis)
        rssi_len = len(rssis)
        average = sum / rssi_len

        var = 0
        for i in rssis:
            var += pow((i-average, 2))
        var /= rssi_len-1

        std = math.sqrt(var)  # 标准差

        sum = 0
        n = 0
        for i in rssis:
            if i >= (average - 1 * std) and i <= (average + 1 * std):
                sum += i
                n += 1
        rssi = sum / n  # 计算出 信标标准浮动值

        return rssi

    def LinearRegression(self, x, y):
        x_mean = 0
        y_mean = 0
        temp1 = 0
        temp2 = 0
